package com.xinqi.modules.chat.chat.friend.service.impl;


import com.alibaba.fastjson.JSONObject;
import com.xinqi.common.core.constant.MQConstants;
import com.xinqi.common.core.enums.RocketMqEnum;
import com.xinqi.common.core.enums.RocketMqRongyunEnum;
import com.xinqi.common.rocketmq.dto.ChatFriendMessageBody;
import com.xinqi.common.rocketmq.dto.MqMessageDTO;
import com.xinqi.common.rocketmq.event.ProducerEvent;
import com.xinqi.modules.chat.chat.friend.domain.ChatFriendEntity;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;


/**
 * 融云私聊操作类MQ
 *
 * @Author：yyzhen
 * @Package：com.xinqi.modules.chat.chat.friend.service.impl
 * @Project：XingqiClass-Cloud-Plus
 * @name：ChatFriendMQService
 * @Date：2023/7/26 10:57
 * @Filename：ChatFriendMQService
 */
@Log4j2
@Service("chatFriendMQService")
@RequiredArgsConstructor
public class ChatFriendMQService {

    /**
     * 融云--私聊--移除黑名单
     *
     * @param friend
     * @return
     */
    @Async("threadPoolTaskExecutor")
    public void privateBlackRemove(ChatFriendEntity friend) {
        ChatFriendMessageBody body = new ChatFriendMessageBody();
        body.setType(RocketMqRongyunEnum.RONGYUN_PRIVATE_BLACK_REMOVE.getCode());
        body.setUserId(friend.getUserId());
        body.setFriendId(friend.getFriendId());
        MqMessageDTO message = new MqMessageDTO(RocketMqEnum.RONGYUN_OPERATION.getCode(), JSONObject.toJSONString(body));
        message.setMessageKey(MQConstants.PRIVATE_MESSAGE_KEY + friend.getUserId());
        ProducerEvent.producerFifoMessage(message);
    }

    /**
     * 融云--私聊--取消免打扰
     *
     * @param friend
     * @return
     */
    @Async("threadPoolTaskExecutor")
    public void privateConversationUnMute(ChatFriendEntity friend) {
        ChatFriendMessageBody body = new ChatFriendMessageBody();
        body.setType(RocketMqRongyunEnum.RONGYUN_PRIVATE_CONVERSATION_UNMUTE.getCode());
        body.setUserId(friend.getUserId());
        body.setFriendId(friend.getFriendId());
        MqMessageDTO message = new MqMessageDTO(RocketMqEnum.RONGYUN_OPERATION.getCode(), JSONObject.toJSONString(body));
        message.setMessageKey(MQConstants.PRIVATE_MESSAGE_KEY + friend.getUserId());
        ProducerEvent.producerFifoMessage(message);
    }

    /**
     * 融云--私聊--取消置顶
     *
     * @param friend
     * @return
     */
    @Async("threadPoolTaskExecutor")
    public void privateConversationUnTop(ChatFriendEntity friend) {
        ChatFriendMessageBody body = new ChatFriendMessageBody();
        body.setType(RocketMqRongyunEnum.RONGYUN_PRIVATE_CONVERSATION_UN_TOP.getCode());
        body.setUserId(friend.getUserId());
        body.setFriendId(friend.getFriendId());
        MqMessageDTO message = new MqMessageDTO(RocketMqEnum.RONGYUN_OPERATION.getCode(), JSONObject.toJSONString(body));
        message.setMessageKey(MQConstants.PRIVATE_MESSAGE_KEY + friend.getUserId());
        ProducerEvent.producerFifoMessage(message);
    }

}
